package indi.h.mlx.sql.util;

import indi.h.mlx.sql.items.SQL;

public class SQLUtil {

	public static SQL sqlJoins(SQL... a) {
		if (a.length == 0)
			return new SQL("", new Object[0]);
		if (a.length == 1)
			return a[0];
		SQL base = sqlJoin(a[0], a[1]);
		for (int i = 2; i < a.length; i++) {
			base = sqlJoin(base, a[i]);
		}
		return base;
	}

	public static SQL sqlJoin(SQL a, SQL b) {
		Object[] o = new Object[a.getData().length + b.getData().length];
		System.arraycopy(a.getData(), 0, o, 0, a.getData().length);
		System.arraycopy(b.getData(), 0, o, a.getData().length, b.getData().length);
		return new SQL(a.getSql() + " " + b.getSql(), o);
	}

}
